package com.jetsum.eduservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jetsum.commonutils.CommonResult;
import com.jetsum.eduservice.entity.EduTeacher;
import com.jetsum.eduservice.entity.vo.TeacherVO;
import com.jetsum.eduservice.service.IEduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 讲师表 前端控制器
 * </p>
 *
 * @author yinh
 * @since 2020-12-30
 */
@Api(tags = "EduTeacherController", description = "讲师功能")
@RestController
@RequestMapping("/eduservice/teacher")
public class EduTeacherController {

    @Autowired
    private IEduTeacherService eduTeacherService;

    @ApiOperation("根据条件分页")
    @PostMapping(value = "/pageByCondition")
    public CommonResult pageByCondition(@RequestBody TeacherVO vo) {
        Page<EduTeacher> page = eduTeacherService.page(new Page<EduTeacher>(vo.getPage(), vo.getSize()), null);
        return CommonResult.success(page);
    }

    @ApiOperation("添加讲师")
    @PostMapping("/saveOrUpdate")
    public CommonResult saveOrUpdate(@RequestBody EduTeacher edu){
        boolean save = eduTeacherService.saveOrUpdate(edu);
        return save?CommonResult.success("成功"):CommonResult.failed("失败");
    }

    @ApiOperation("获取讲师信息")
    @GetMapping("/get/{id}")
    public CommonResult getById(@PathVariable Long id){
        return CommonResult.success(eduTeacherService.getById(id));
    }

    @ApiOperation("删除讲师信息")
    @DeleteMapping("/deleteById/{id}")
    public CommonResult deleteById(@PathVariable Long id){
        boolean remove = eduTeacherService.removeById(id);
        return remove?CommonResult.success("成功"):CommonResult.failed("失败");
    }

}

